package com.letv.whatslive.model.convert;

import com.letv.whatslive.model.GuideImageSrc;
import com.letv.whatslive.model.utils.ObjUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * Created by Administrator on 2015/12/30.
 */
public class GuideImageSrcConvert {
    public static DBObject castGuideImageSrcToDBObject(GuideImageSrc guideImageSrc) {
        DBObject dbo = new BasicDBObject();
        if (guideImageSrc.getId() != null) {
            dbo.put("_id", guideImageSrc.getId());
        }
        dbo.put("picType", ObjUtils.toInteger(guideImageSrc.getPicType(), 0));
        dbo.put("picName", ObjUtils.toString(guideImageSrc.getPicName(), ""));
        dbo.put("picUrl", ObjUtils.toString(guideImageSrc.getPicUrl(), ""));
        dbo.put("createTime", ObjUtils.toLong(guideImageSrc.getCreateTime(), 0l));
        dbo.put("updateTime", ObjUtils.toLong(guideImageSrc.getUpdateTime(), 0l));
        dbo.put("startTime", ObjUtils.toLong(guideImageSrc.getStartTime(), 0l));
        dbo.put("endTime", ObjUtils.toLong(guideImageSrc.getEndTime(), 0l));
        dbo.put("showTime", ObjUtils.toLong(guideImageSrc.getShowTime(), 0l));
        dbo.put("isOpen", ObjUtils.toInteger(guideImageSrc.getIsOpen(), 0));
        return dbo;
    }

    public static GuideImageSrc castDBObjectToGuideImageSrc(DBObject dbObject) {
        GuideImageSrc guideImageSrc = new GuideImageSrc();
        if (dbObject != null) {
            guideImageSrc.setId(ObjUtils.toLong(dbObject.get("_id")));
            guideImageSrc.setPicType(ObjUtils.toInteger(dbObject.get("picType")));
            guideImageSrc.setPicName(ObjUtils.toString(dbObject.get("picName")));
            guideImageSrc.setPicUrl(ObjUtils.toString(dbObject.get("picUrl")));
            guideImageSrc.setCreateTime(ObjUtils.toLong(dbObject.get("createTime")));
            guideImageSrc.setUpdateTime(ObjUtils.toLong(dbObject.get("updateTime")));
            guideImageSrc.setStartTime(ObjUtils.toLong(dbObject.get("startTime")));
            guideImageSrc.setEndTime(ObjUtils.toLong(dbObject.get("endTime")));
            guideImageSrc.setShowTime(ObjUtils.toLong(dbObject.get("showTime")));
            guideImageSrc.setIsOpen(ObjUtils.toInteger(dbObject.get("isOpen")));

        }
        return guideImageSrc;
    }
}
